package com.carkeeper.servcieManagement.controller;

import com.carkeeper.common.utils.Result;
import com.carkeeper.common.utils.StatusCode;
import com.carkeeper.servcieManagement.service.ServiceServcie;
import com.carkeeper.serviceManagement.pojo.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author pengjinxiong
 * @version 1.0
 * @date 2020/11/24 14:16
 */
@RestController
@CrossOrigin
@RequestMapping("/service")
public class ServiceController {

    @Autowired
    private ServiceServcie serviceServcie;

    //根据id查询服务目录
    @GetMapping("/findListById/{serviceId}")
    public List<Service> findListById(@PathVariable("serviceId") String serviceId) {
        Map<String, Object> searchMap = new HashMap();
        if (!"all".equals(serviceId)) {
            searchMap.put("id", Long.parseLong(serviceId));
        }
        searchMap.put("status", "1");
        List<Service> list = serviceServcie.findList(searchMap);
        return list;
    }


    /**
     * 商品上下架
     *
     * @param id
     * @return
     */
    @PutMapping("/put/{id}/{status}")
    public Result put(@PathVariable Long id, @PathVariable String status) {
        serviceServcie.put(id, status);
        return new Result(true, StatusCode.OK, "执行成功");
    }

}
